// api/file_api/file_upload.go
package file_api

import (
	"github.com/gin-gonic/gin"
	"github.com/sirupsen/logrus"
	"muziai-server/utils/res"
	"path"
)

func (FileApi) FileUploadView(c *gin.Context) {
	fileHeader, err := c.FormFile("file") // 单个文件
	if err != nil {
		res.FailWithMsg(c, "请选择文件")
		return
	}

	filePath := path.Join("uploads", "safe", fileHeader.Filename)
	err = c.SaveUploadedFile(fileHeader, filePath)
	if err != nil {
		logrus.Error(err)
		res.FailWithError(c, err)
		return
	}

	// 返回文件路径
	res.OkWithData(c, filePath)
}
